<?php
namespace Inationsoft\NS\Net;

use Inationsoft\NS\Object;
use Inationsoft\NS\Exception\LibraryException;
use Inationsoft\NS\Exception\DatabaseException;

/**
 *Handle LDAP protocol functionality
 *
 *@author Inanta Martsanto <inanta@inationsoft.com>
 */
class LDAP extends Object {
	private $_connection;

	function bind($username, $password) {
		if(ldap_bind($this->_connection, $username, $password) === true) return true;

		throw new Exception('Binding error');
	}

	function __construct($host) {
		if(!function_exists('mysql_connect')) throw new LibraryException(array('code' => NS_EX_LIB_NOT_INSTALLED, 'class' => __CLASS__, 'library' => 'LDAP'));
		if(!$this->_connection = \ldap_connect($host)) throw new Exception('Cannot connect to LDAP server [' . $host . ']');
	}

	function __destruct() {
		ldap_close($this->_connection);
	}
}
?>
